type Optional<T> = T | null | undefined;

export interface BillingType {
    value: string;
    name: string;
    translate?: string;
}

export const BillingTypes: BillingType[] = [
    {
        value: 'TRADE_ORDER',
        name: '支付',
    },
    {
        value: 'WITHDRAWAL',
        name: '转出',
    },
    {
        value: 'DEPOSIT',
        name: '转入',
    },
    {
        value: 'WITHDRAWAL_CASH',
        name: '提现'
    },
    {
        value: 'RECHARGE',
        name: '充值'
    }
];

export function getBillingTypesByName(name: string): Optional<BillingType> {
    const index = BillingTypes.findIndex(bt => bt.name === name);
    if (index > -1) {
        return BillingTypes[index];
    } else {
        return null;
    }
}

export function getBillingTypesByValue(value: string): Optional<BillingType> {
    const index = BillingTypes.findIndex(bt => bt.value === value);
    if (index > -1) {
        return BillingTypes[index];
    } else {
        return null;
    }
}
